import React, { Component } from 'react'
import {ListBox} from '../../components'
import UpdateUserPage from './Update'
import { Modal } from 'antd';

export default class ListUserPage extends Component {
    constructor(props) {
        super(props);
        //行操作列表
        this.rowOperation = [
            // {
            //     handleName: 'edit',
            //     iconClass: 'cellEdit'
            // },{
            //     handleName: 'delete',
            //     iconClass: 'cellDele'
            // },{
            //     handleName: 'assignRole',
            //     iconClass: 'cellRole'
            // }
            {
                handleName: 'doubleClick',
                showName: '行双击事件'
            }
        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'addUser',
                showName: '新增',
                iconClass: 'plus'
            },{
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit'
            },{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete'
            },{
                handleName: 'assignRole',
                showName: '分配角色',
                iconClass: 'key'
            },{
                handleName: 'export',
                showName: '导出',
                iconClass: 'export'
            }

        ];

        //table列表展示列配置
        //storageKey 本地存储的key
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏（用于列配置显示隐藏）, foreverHidden: true 列永久隐藏
        this.tableColumn = {
            storageKey: 'ListUserColumnConfig',
            data: [
                {
                    showName: 'id',
                    columnName: 'userId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '登录账户名',
                    columnName: 'loginName',
                    columnWidth: 130
                },{
                    showName: '人员姓名',
                    columnName: 'userName'
                },{
                    showName: '邮件地址',
                    columnName: 'email',
                    columnHidden: true
                },{
                    showName: '座机号',
                    columnName: 'phone'
                },{
                    showName: '手机号',
                    columnName: 'mobile',
                    columnWidth: 130
                },{
                    showName: '是否可登录',
                    columnName: 'loginFlag',
                    showOption:[//页面显示配置
                        {
                            optionKey:'1',
                            optionShow:'是'
                        },{
                            optionKey:'0',
                            optionShow:'否'
                        }
                    ]
                },/*{
                 showName: '最后登录IP',
                 columnName: 'loginIp'
                 },*//*{
                 showName: '最后登录时间',
                 columnName: 'loginDate'
                 },*//*{
                 showName: '是否初始化标志',
                 columnName: 'initFlag'
                 },{
                 showName: '最后密码修改时间',
                 columnName: 'lastPwdModifed'
                 },*/{
                    showName: '创建人',
                    columnName: 'createBy'
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreateStr'
                },{
                    showName: '更新人',
                    columnName: 'lastModifiedBy'
                },{
                    showName: '更新时间',
                    columnName: 'gmtModified'
                }/*,{
                 showName: '有效标志',
                 columnName: 'activeFlag'
                 }*/
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        //      5、下拉框 type='disabled'
        this.searchComponentData = [
            {
                showName: '登录账户名',
                name:'loginName',
                type: 'input',
                url: null
            },{
                showName: '人员姓名',
                name:'userName',
                type: 'input',
                url: null
            },{
                showName: '手机号',
                name:'mobile',
                type: 'number',
                maxName:'mobileMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'mobileMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                showName: '座机号',
                name:'phone',
                type: 'disabled',
            },{
                showName: '创建时间',
                name:'gmtCreateStr',
                type: 'date',
                maxName:'gmtCreateMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'gmtCreateMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                showName : '是否可登录',
                name : 'loginFlag',
                type : 'select',
                optionList:[//下拉框的信息
                    //下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'是'
                    },{
                        optionKey:'0',
                        optionShow:'否'
                    }
                ]
            },{
                showName : '动态获取下拉框内容',
                name : 'email',
                type : 'select',
                url: '/base/getSelectData',
                condition: { //查询条件
                    name: '123',
                    type: '1'
                }
            }
        ];

    }

    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'edit'){
            this.editHandle(rowObj);
        }else if(strHandles === 'delete'){
            this.deleteHandle(rowObj);
        }else if(strHandles === 'addUser'){
            this.addUserHandle();
        }else if(strHandles == 'assignRole'){
            this.assignRoleHandle(rowObj);
        }else if(strHandles == 'doubleClick'){
            this.infoHandle(rowObj);
        }else if(strHandles == 'export'){
            this.exportHandle(rowObj);
        }
    }
    infoHandle = (rowObj) => {

        console.log("行双击事件：", rowObj);

    }

    exportHandle= (conditonData) => {
        console.log("导出数据conditonData============", conditonData);
    }

    // 增加用户
    addUserHandle = () => {
        this.refs.updateUser.getFormData[1]={
            type : 'input',
            showName : '登录用户名',
            name : 'loginName',
            initialValue : '',
            required:'required',
            disable: false
        };
        this.refs.updateUser.addUserHandle();
    }

    editHandle = (rowObj) => {
        this.refs.updateUser.getFormData[1]={
            type : 'input',
            showName : '登录用户名',
            name : 'loginName',
            initialValue : '',
            required:'required',
            disable: true
        };
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateUser.editHandle(rowObj[0].data);
        }
    }

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateUser.deleteHandle(rowObj[0].data)
        }
    }

    assignRoleHandle = (rowObj) =>{
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            //传递参数--用户id
            let userId = rowObj[0].data.userId;
            this.refs.assignRole.initModal(userId);
        }
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.listUser.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'listUser'
					title='用户数据列表'
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/base/auth/user/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
					isRowSingle={true}
                />

                <UpdateUserPage
                    ref="updateUser"
                    refreshHandle = {this.refreshHandle}
                />


                {/*<AddUserPage*/}
                {/*ref="AddUser"*/}
                {/*addUrl=""*/}
                {/*/>*/}

            </div>
        )
    }
}
